package main

import (
	"flag"
	"log"
	"zin/app/console"
	"zin/config"
	"zin/framework"
	"zin/framework/provider/app"
	"zin/framework/provider/env"
	"zin/framework/util"
)

var baseFolder string

func main() {

	// 解析baseFolder
	flag.StringVar(&baseFolder, "base_folder", "", "base_folder参数, 默认为当前路径")
	flag.Parse()
	if baseFolder == "" {
		baseFolder = util.GetExecDirectory()
	}

	container := framework.NewFmkContainer()
	util.SetContainer(container)

	var err error

	// env provider
	err = container.Bind(&env.ProviderEnv{BaseFolder: baseFolder})
	if err != nil {
		log.Fatalln("绑定env容器发生错误", err)
	}

	//配置解析
	config.InitConfig(baseFolder)

	// env provider
	err = container.Bind(&app.ProviderApp{BaseFolder: baseFolder})
	if err != nil {
		log.Fatalln("绑定app容器发生错误", err)
	}

	err = console.RunCommand(container)
	if err != nil {
		log.Fatalln("发生错误: ", err)
	}

}
